<?php

setlocale (LC_TIME, 'fr_FR'); 

function viewDate($date){
  $date = date("Y-m-d", strtotime($date)); 
  if($date == date('Y-m-d')) return 'Aujourd\'hui';  
  else if(strtotime($date) == strtotime(date('Y-m-d').' - 1 DAY')) return 'Hier';
  else if(strtotime($date) == strtotime(date('Y-m-d').' - 2 DAY')) return 'Avant hier';
  else return strftime("%A %d %B %Y",strtotime("$date"));
}
 
echo viewDate('2013-06-10 23:24:14');
$tab_photos =  $wpdb->get_var("SELECT COUNT(id)AS total FROM wp_galerie WHERE statut='1'");
$photos_par_page = 50;
$nbre_photos = $tab_photos;

if($nbre_photos>$photos_par_page){
  
     $total_page = ceil($nbre_photos/$photos_par_page);
  
	if(isset($_GET['page'])) // Si la variable $_GET['page'] existe...
	{
	     $pageActuelle=$_GET['page'];
	     
	     if($pageActuelle>$total_page) // Si la valeur de $pageActuelle (le num�ro de la page) est plus grande que $nombreDePages...
	     {
	          $pageActuelle=$total_page;
	     }
	}
	else // Sinon
	{
	     $pageActuelle=1; // La page actuelle est la n�1    
	}
	//$photos = $requette->selectPhotosValidesLimit(($pageActuelle-1)*$photos_par_page,$photos_par_page);	
	$photos = $wpdb->get_results("SELECT * FROM wp_galerie WHERE statut='1' order by id desc LIMIT $page, 50 ");
}
else{
	//$photos = $requette->selectPhotosValides();
	$photos = $wpdb->get_results("SELECT * FROM wp_galerie WHERE statut='1' ");
}	
	
?>	
	
	<div id="respond">
	<div id="titre_galerie">
	</div>
		<div id="demo" class="wrap">
	<?php foreach($photos as $photo){
	
	      if($photo->statut="1"){
			if(isset($photo->id)){
	
				      $id = $photo->id;
	
					  $dirname = 'C:\xampp\htdocs\projet-lpst-wp\wp-content\photos\\'.$id.'\\';
                      
                      if(is_dir($dirname)){
						$dir = opendir($dirname);
	
						//$i = 1;
	
						while ($fichier = readdir($dir)){  
	
						//$tab_image[$i] = $fichier;
	
							 if(is_file($dirname.$fichier)) {
							  $width = 230;
							  $image =getimagesize($dirname.'/'.$fichier);
							  $reduction = (($width * 100)/$image[0] );
							  $height = ( ($image[1] * $reduction)/100 );
							 ?>
							  <div class="box">
							     
							      <a rel="images" title="<?php echo ucfirst($photo->prenom).' - '.substr($photo->cp, 0, -3);?>" class="lightbox" href="<?php echo 'http://localhost/projet-lpst-wp/wp-content/photos/'.$id.'/'.$fichier; ?>" ><img width="230px" height="<?php echo $height; ?>" src="<?php echo 'http://localhost/projet-lpst-wp/wp-content/photos/'.$id.'/'.$fichier; ?>" /></a>
                                  <p><?php if(isset($photo->date_poste)&& ($photo->date_poste != '0000-00-00 00:00:00')){echo viewDate($photo->date_poste);} ?></p>
                                 <div class="res-soc">
                                  <div class="fb-like" data-href="http://tousformidables.fr<?php echo '/wp-content/photos/'.$id.'/'.$fichier; ?>" data-send="false" data-layout="button_count" data-width="450" data-show-faces="true"></div>
                                  <a href="https://twitter.com/share" class="twitter-share-button" data-url="http://tousformidables.fr" data-lang="fr">Tweet</a>
                                  <p class="g-plusone" data-size="small"></p>
                                 </div> 
							  </div>
		   <?php             }
				        }
				     }
                   }
			     }
	         }
			?>
			</div>
			<div class="pagination">
			
				<?php  
				if($nbre_photos>$photos_par_page){
				  echo "Page";
					for($i=1; $i<=$total_page; $i++) //On fait notre boucle
					{
				     //On va faire notre condition
				     if($i==$pageActuelle) //Si il s'agit de la page actuelle...
				     {
				         echo ' [ '.$i.' ] '; 
				     }	
				     else //Sinon...
				     {
				          echo '<a href="galerie_arbitres.php?page='.$i.'">'.$i.'</a> ';
				     }
					}
				}
				?>
			</div>
	</div>
<script type="text/javascript"> 
	// wait for the DOM to be loaded 
	jQuery(function() { 
		jQuery('#demo').masonry({
		  singleMode: true, 
		  itemSelector: '.box' 
		});
	 jQuery("a.lightbox").fancybox({
		  'titleShow'		: true,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic'
		});
	});	
</script>